package com.cupk.Dao;

import com.cupk.pojo.Orders;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface OrdersMapper {
//这里传的user_id=#{id}是后边的id是主键id,是users表的，传给orders表的外键的。
    @Select("select * from t_orders where user_id=#{id}")
    @Results({
            @Result(id=true,column = "id",property = "id"),
            @Result(column = "number",property = "number")
    })
    List<Orders> selectOrdersByUserId(int user_id);
    //注意这里的传参int user_id!!!


    @Select("select * from t_orders where id=#{id}")
    @Results({
            @Result(id=true,column = "id",property = "id"),
            @Result(column = "number",property = "number"),
            @Result(column = "id",property = "productList",many=@Many(select="com.cupk.Dao.ProductMapper.selectProductByOrdersId"))
    })
    Orders selectOrdersById(int id);
}
